<template>
  <div class="zjb_xiang">
    <!-- 详情页面布局开始 -->
    <div class="zjb_xiang_con">
      <div class="zjb_xiang_header">
        <!-- 头部布局开始 -->
        <span>
          <img
            @click="zjb_goHome"
            src=""
            alt
          />
        </span>
        <p>讲师详情</p>
        <!-- 头部布局结束 -->
      </div>
      <div class="zjb_xiang_head_bottom">
        <!-- 标签布局开始 -->
        <ul>
          <li>
            <img :src="x.avatar" alt="教师图片" />
            <div class="zjb_xiang_right">
              <div>
                <p>
                  {{x.teacher_name}}
                  <span>{{x.level_name}}</span>
                </p>
                <p v-if="x.sex==0">
                  男
                  <span>{{x.teach_age}}年教龄</span>
                </p>
                <p v-if="x.sex==1">
                  女
                  <span>{{x.teach_age}}年教龄</span>
                </p>
                <span v-for="(v,i) in x.tag_content" :key="i" class="span">{{v}}</span>
              </div>
              <p @click="zjb_guan" v-show="!flg">关注</p>
              <p @click="zjb_guan" v-show="flg">已关注</p>
            </div>
          </li>
        </ul>
        <!-- 标签布局结束 -->
      </div>
      <div class="zjb_xiang_con_tab">
        <!-- 选项卡布局开始 -->
        <van-tabs>
          <van-tab title="讲师介绍" class="zjb_xiang_jie">
            <ul>
              <li>
                <p>
                  {{xx.attr[0].attr_name}}
                  <span>{{xx.attr[0].attr_value[0].attr_value_name}}</span>
                </p>
                <p>
                  {{xx.attr[1].attr_name}}
                  <span>{{xx.attr[1].attr_value[0].attr_value_name}}</span>
                </p>
                <div>
                  <p>老师简洁</p>
                  <span class="zjb_xiang_jie_span">{{xx.intro}}</span>
                </div>
              </li>
            </ul>
          </van-tab>
          <van-tab title="主讲课程">
            <p class="zjb_xiang_jie_con_two"></p>
          </van-tab>
          <van-tab title="学员评价" class="zjb_xiang_jie_con_three">
            <img src="https://wap.365msmk.com/img/empty.0d284c2e.png" alt />
            <p>暂无评论</p>
          </van-tab>
        </van-tabs>
        <!-- 选项卡布局结束 -->
      </div>
    </div>

    <div class="zjb_xiang_footer">
      <!-- 尾部布局开始 -->
      <p @click="zjb_tiao">立即报名</p>
      <!-- 尾部布局结束 -->
    </div>
    <!-- 详情页面布局结束 -->
  </div>
</template>

<script>
import http1 from "../../uti/http";
import http from "../../http/http";
export default {
  name: "xiang",
  beforeRouteLeave(to,from,next){
    if(to.name=='home'){
      to.meta.keepAlive=true;
      from.meta.keepAlive=false;
    }
    next();
  },
  data() {
    return {
      id: "",
      flg: false,
      title: "关注 ",
      x: {},
      xx: {}
    };
  },
  mounted() {
    //--->接受首页点击，传递过来的id
    this.id = this.$route.query.id;
    var id = this.$route.query.id;
    var token = this.$store.state.User.token;
    this.$http1
      .get("/api/app/teacher/" + id + "?", {
        headers: { Authorization: "Bearer " + token }
      })
      .then(res => {
        console.log(res);
        this.x = res.teacher;
      });
    // var show_id=http('get','https://www.365msmk.com/api/app/teacher/'+id+'?',{ headers: { Authorization: "Bearer " + token }});
    // show_id.then(res=>{
    //     // console.log(res)
    //     this.x=res.data.data.teacher;
    //     // console.log(res.data.data.teacher)
    // });
    this.$http1
      .get("/api/app/teacher/info/" + id + "?", {
        headers: { Authorization: "Bearer " + token }
      })
      .then(res => {
        console.log(res);
        this.xx = res;
      });
    //   var show2=http('get','https://www.365msmk.com/api/app/teacher/info/'+id+'?',{ headers: { Authorization: "Bearer " + token }});
    // show2.then(res=>{
    //     console.log(res)
    //     this.xx=res.data.data;
    //     console.log(this.xx)
    // });
  },
  methods: {
    zjb_goHome() {
      //--->点击箭头，返回首页
      this.$router.go(-1);
    },
    zjb_guan() {
      //--->点击关注
      this.flg = !this.flg; //--->取反
      if (!this.flg) {
        this.$toast.success("已取消");
        var token = this.$store.state.User.token;
        this.$http1
          .get("/api/app/teacher/collect/" + this.id + "?", {
            headers: { Authorization: "Bearer " + token }
          })
          .then(res => {
            this.$http1
              .get("/api/app/teacher/" + this.id + "?", {
                headers: { Authorization: "Bearer " + token }
              })
              .then(res => {
                console.log(res);
                this.$store.commit("guan", ret.data.data.teacher);
              });
          });
        // var ao=http('get','https://www.365msmk.com/api/app/teacher/collect/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
        // ao.then(res=>{
        //     if(res.data.code==200){
        //         var a=http('get','https://www.365msmk.com/api/app/teacher/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
        //         a.then(ret=>{
        //             console.log(ret);
        //             this.$store.commit('guan',ret.data.data.teacher);
        //         })
        //     }
        // })
      } else {
        this.$toast.success("已关注");
        var token = this.$store.state.User.token;
        this.$http1
          .get("/api/app/teacher/collect/" + this.id + "?", {
            headers: { Authorization: "Bearer " + token }
          })
          .then(res => {
            this.$http1
              .get("/api/app/teacher/" + this.id + "?", {
                headers: { Authorization: "Bearer " + token }
              })
              .then(res => {
                console.log(res);
                this.$store.commit("guan", ret.data.data.teacher);
              });
          });
        // var ao=http('get','https://www.365msmk.com/api/app/teacher/collect/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
        // ao.then(res=>{
        //     if(res.data.code==200){
        //         var a=http('get','https://www.365msmk.com/api/app/teacher/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
        //         a.then(ret=>{
        //             console.log(ret);
        //             this.$store.commit('guan',ret.data.data.teacher);
        //         })
        //     }
        // })
      }
    },
    zjb_guan1() {
      //-->点击取消关注
      //     this.flg=!this.flg;//--->取反
      //     this.$toast.success('已取消');
      //     var token=this.$store.state.User.token;
      // var ao=http('get','https://www.365msmk.com/api/app/teacher/collect/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
      // ao.then(res=>{
      //     if(res.data.code==200){
      //         var a=http('get','https://www.365msmk.com/api/app/teacher/'+this.id+'?',{ headers: { Authorization: "Bearer " + token }});
      //         a.then(ret=>{
      //             console.log(ret);
      //             this.$store.commit('guan',ret.data.data.teacher);
      //         })
      //     }
      // })
    },
    zjb_tiao() {//--->点击立即报名，跳转页面
     this.$router.push({ name: "bao", query: { id: this.id } });
    }
  }
};
</script>

<style scoped lang="scss">
.span {
  width: auto;
  height: 0.4rem;
  line-height: 0.4rem;
  border-radius: 0.16rem;
  background: orange;
  color: red;
  font-size: 0.14rem;
  text-align: center;
  margin-right: 0.1rem;
  padding: 0 0.1rem;
}
.zjb_xiang {
  height: 100%;
  font-size: 0.16rem;
  line-height: 0.2rem;
  width: 6.4rem;
  background: rgb(240, 242, 245);
  display: flex;
  flex-direction: column;
}
.zjb_xiang_con {
  flex: 1;
  overflow: auto;
  position: relative;
}
.zjb_xiang_header {
  height: 1.7rem;
  background: linear-gradient(180deg, #63b7fe, #4e7de3);
  display: flex;
  & > span {
    display: inline-block;
    width: 0.6rem;
    height: 0.75rem;
    //    border: 1px solid #000;
    text-align: center;
    line-height: 0.9rem;
    & > img {
      height: 0.27rem;
      width: 0.15rem;
      // border: 1px solid #000;
      font-size: 0.4rem;
    }
  }
  & > p {
    height: 0.75rem;
    width: 5.37rem;
    //    border: 1px solid #000;
    font-size: 0.3rem;
    text-align: center;
    line-height: 0.75rem;
    color: #fff;
  }
}
.zjb_xiang_head_bottom {
  position: absolute;
  top: 0.7rem;
  left: 0.16rem;
  width: 6.06rem;
  height: 1.55rem;
  // border: 1px solid #000;
  // margin: 0 auto;
  background: #fff;
  border-radius: 0.08rem;
  ul {
    width: 5.55rem;
    height: 1.3rem;
    //  border: 1px solid #000;
    margin: 0 auto;
    li {
      height: 100%;
      display: flex;
      align-items: center;
      & > img {
        width: 0.68rem;
        height: 0.68rem;
        margin-right: 0.2rem;
      }
      & > .zjb_xiang_right {
        display: flex;

        & > div {
          width: 3.6rem;
          height: 0.56rem;
          //   border: 1px solid #000;
          padding: 0.1rem 0;
          & > p:nth-child(1) {
            font-size: 0.25rem;
            color: #595959;
            & > span {
              font-size: 0.18rem;
              color: #ea7a2f;
              margin-left: 0.1rem;
            }
          }
          & > p:nth-child(2) {
            font-size: 0.2rem;
            color: #b7b7b7;
            margin-top: 0.2rem;
            & > span {
              font-size: 0.18rem;
              color: #b7b7b7;
              margin-left: 0.08rem;
            }
          }
        }
        & > p:nth-child(2) {
          font-size: 0.25rem;
          margin-top: 0.14rem;
          width: 1.05rem;
          height: 0.48rem;
          //  border: 1px solid #000;
          text-align: center;
          line-height: 0.48rem;
          background: #ebeefe;
          font-size: 0.22rem;
          color: red;
          border-radius: 0.4rem;
        }
        & > p:nth-child(3) {
          margin-top: 0.24rem;
          font-size: 0.25rem;
          margin-left: 0.16rem;
          color: #b7b7b7;
        }
      }
    }
  }
}
.zjb_xiang_con_tab {
  margin-top: 1rem;
}
>>> .van-tab--active {
  color: #ea7a2f;
  font-size: 0.25rem;
}
>>> .van-tab {
  font-size: 0.25rem;
}
>>> .van-ellipsis {
  height: 0.76rem;
  line-height: 0.76rem;
}
>>> .van-tabs .van-tabs--line {
  height: 0.76rem;
  line-height: 0.76rem;
}
>>> .van-tabs--line .van-tabs__wrap {
  height: 0.76rem;
  line-height: 0.76rem;
}
>>> .van-tabs__line {
  width: 0.43rem !important;
}
>>> .van-tabs__content {
  background: #fff;
}
.zjb_xiang_footer {
  width: 100%;
  height: 1rem;
  background: #eb6100;
  color: #fff;
  font-size: 0.4rem;
  font-weight: 400;
  text-align: center;
  line-height: 1rem;
}
.zjb_xiang_jie {
  width: 100%;
  height: auto;
  ul {
    padding-top: 0.2rem;
    li {
      width: 5.8rem;
      height: 6rem;
      // border: 1px solid #000;
      margin: 0 auto;
      & > p {
        margin-bottom: 0.4rem;
        font-size: 0.22rem;
        color: #b7b7b7;
        & > span {
          margin-left: 0.4rem;
        }
      }
      & > div {
        display: flex;
        & > p {
          font-size: 0.22rem;
          color: #b7b7b7;
        }
        & > .zjb_xiang_jie_span {
          display: block;
          width: 4rem;
          height: auto;
          //    border: 1px solid #000;
          margin-left: 0.4rem;
          font-size: 0.22rem;
          color: #b7b7b7;
          line-height: 0.4rem;
        }
      }
    }
  }
}
.zjb_xiang_jie_con_two {
  height: 0.4rem;
}
.zjb_xiang_jie_con_three {
  height: 3.15rem;
  width: 100%;
  text-align: center;
  & > img {
    width: 2.56rem;
    height: 2.56rem;
  }
  & > p {
    color: #b7b7b7;
    font-size: 0.3rem;
    margin-top: 0.2rem;
  }
}
</style>